package action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import vo.Product;

import com.opensymphony.xwork2.ActionSupport;

import flexjson.JSONSerializer;





public class BaseAction extends ActionSupport{
	
	HttpServletResponse response = ServletActionContext.getResponse();
	HttpServletRequest request = ServletActionContext.getRequest();
	//查找所有的学生信息并分页
	@SuppressWarnings("unchecked")
	public void writeJson(Object o) throws Exception 
	{  
		 try {
 			
			
			
			 PrintWriter out=response.getWriter();
			  //转换成json
			   JSONSerializer json = new JSONSerializer();
		       
		       String  jsonStr =json.serialize(o);
		       JSONObject object = new JSONObject();
		       object.put("returndata",jsonStr);
		  
		      
		       System.out.println(object);
		      out.print(object);
		      out.flush();
		      out.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	     
        
		
	}
	public HttpServletResponse getResponse() {
		return response;
	}
	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}
	public HttpServletRequest getRequest() {
		return request;
	}
	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}
	
	
	}
	
	
	

